package com.shuoyue.ycgk.utils;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;
import com.shuoyue.ycgk.R;

import static com.bumptech.glide.request.RequestOptions.bitmapTransform;

public class GlideUtil {

    public static void loadImage(Context mContext, String url, ImageView imageView) {
        Glide.with(mContext).load(url)
                .placeholder(R.mipmap.img_loading_gray)
                .error(R.mipmap.img_loading_gray)
                .into(imageView);
    }

    public static void loadImage(Context mContext, int src, ImageView imageView) {
        Glide.with(mContext).load(src)
                .placeholder(R.mipmap.img_loading_gray)
                .error(R.mipmap.img_loading_gray)
                .into(imageView);
    }

    public static void loadImage(Context mContext, String url, int error, ImageView imageView) {
        Glide.with(mContext).load(url)
                .placeholder(error)
                .error(error)
                .into(imageView);
    }


    /**
     * 圆形图片
     *
     * @param mContext
     * @param url
     * @param error
     * @param imageView
     */
    public static void loadImageCircular(Context mContext, String url, int error, ImageView imageView) {
        Glide.with(mContext).load(url).apply(bitmapTransform(new CircleCrop()).error(error).placeholder(error).fallback(error).diskCacheStrategy(DiskCacheStrategy.ALL)).into(imageView);
    }

    public static void loadImageCircular(Context mContext, int url, int error, ImageView imageView) {
        Glide.with(mContext).load(url).apply(bitmapTransform(new CircleCrop()).error(error).placeholder(error).fallback(error).diskCacheStrategy(DiskCacheStrategy.ALL)).into(imageView);
    }

}
